home *** CD-ROM | disk | FTP | other *** search
- Path: kbad.eglin.af.mil!rpi!not-for-mail
- From: kanze@gabi-soft.fr (J. Kanze)
- Newsgroups: comp.lang.c++,comp.lang.c++.moderated
- Subject: Re: Enumerated type converted to pointer? Legal?
- Followup-To: comp.lang.c++,comp.lang.c++.moderated
- Date: 14 Mar 1996 17:56:34 -0000
- Organization: GABI Software, Sarl.
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: rmartin@oma.com
- Message-ID: <4i9mki$ge5@netlab.cs.rpi.edu>
- References: <4hobji$mco@netlab.cs.rpi.edu> <4i703u$1gl@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
- X-Original-Date: 14 Mar 1996 11:58:25 GMT
-
- In article <4i703u$1gl@netlab.cs.rpi.edu> shappir@libra.math.tau.ac.il
- (Shappir Dan) writes:
-
- |> { comp.std.c++ removed from followups. -mod}
-
- |> Brad Stowers (bstowers@pobox.com) wrote:
-
- |> : Compile and run the above program. Is it just me, or should the last line
- |> : of the main() function ( FooBar(x, mdType1); ) have caused a type mismatch
- |> : error? I think I know why it didn't: mdType1 evaluates to an integer with
- |> : a value of 0, which is a valid value to pass as a pointer. In support of
- |> : this theory, the line:
-
- |> This is due to one of the differences between C and C++. In C the NULL
- |> pointer is defined as ((void*)0) while in C++ it's simply 0.
-
- This is false. In both C and C++, the exact definition of NULL depends
- on the implementation. On most Unix systems, for example, both are
- defined as 0, but I have worked on systems (before C++) where NULL was
- 0L.
-
- The only difference between C and C++ in this regard is that ((void*)0)
- is legal in C, but not in C++. The only reason that an implementor
- would maintain different definitions is historical: he used ((void*)0)
- in C before implementing C++, and is afraid that changing it would break
- customer code. (In fact, any code it broke was already broken, but it
- is often easier for the implementor to support the broken code that to
- explain to the customer why it worked in one release and not in the
- next.)
-
- |> This can raise
- |> all sorts of type conversion problems, for example:
-
- |> void foo(int bar) { ... }
- |> void foo(void* bar) { ... }
-
- |> ...
- |> foo(0);
- |> ...
-
- |> The compiler will not be able to determine which version of foo to call.
-
- The compiler had better call `foo( int )', which is an exact match.
- More surprising, since NULL is generally defined as 0, `foo( NULL )'
- also calls `foo( int )'. (Fergus Henderson once modified g++ to have a
- real null pointer, which would only match pointer types, but his
- modifications are not part of the standard, and as far as I know, have
- never been incorporated in a real g++ release.)
- --
- James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
- GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
- Conseils, Θtudes et rΘalisations en logiciel orientΘ objet --
- -- A la recherche d'une activitΘ dans une region francophone
-
- [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
- [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
- [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
- [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
-